package com.cy.duosearch.langchain.agent;

import com.cy.duosearch.langchain.tool.*;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Data
public abstract class Agent {

    public abstract ChatLanguageModel getLanguageModel();

    public abstract ChatMemory getMemory();

    public abstract String getPrompt();

    public List<Tool> tools = List.of(new FileSaverTool(), new SearchTool(), new TerminateTool());

    // avoid death circle , set max recycle times
    private int maxSteps = 10;

    private int currentStep = 0;

    public abstract ToolResult step();

    public void run() {

        AgentState state = AgentState.RUNNING;
        while (currentStep < maxSteps && state!= AgentState.FINISHED) {

            currentStep++;

            log.info("Step : {} / {} ", currentStep, maxSteps);

            ToolResult result = step();
            state = result.getState();


            if (currentStep >= maxSteps) {
                log.info("Max steps reached "+currentStep);
            }

        }
    }

}
